package uk.co.droidinactu.common.model;

import java.util.ArrayList;
import java.util.HashMap;

import android.provider.BaseColumns;

/**
 * this object is used to define any data that is made up of key/value pairs.
 * 
 * @author andy
 */
public abstract class AbstractTypeObject extends AbstractDataObj {

    protected static String FIELD_NAME_TYPE_NAME = "typename";
    protected static String FIELD_NAME_TYPE_VALUE = "typevalue";
    protected String name = "";
    protected String description = "";

    /**
     * Default Constructor.
     */
    public AbstractTypeObject() {
    }

    /**
     * Constructor used for creating an Animal from a Database Row.
     * 
     * @param arow
     */
    public AbstractTypeObject(final HashMap<String, String> arow) {
        super(arow);
        name = arow.get(AbstractTypeObject.FIELD_NAME_TYPE_NAME);
        description = arow.get(AbstractTypeObject.FIELD_NAME_TYPE_VALUE);
    }

    /**
     * gets the description for this type.
     * 
     * @return
     */
    public String getDescription() {
        return description;
    }

    /**
     * return the field descriptions that make up a row in this table.
     */
    @Override
    public HashMap<Integer, ArrayList<String>> getFields() {
        final HashMap<Integer, ArrayList<String>> fields = new HashMap<Integer, ArrayList<String>>();

        int x = 1;
        fields.put(x++, getArrayList(BaseColumns._ID, "INTEGER PRIMARY KEY"));
        fields.put(x++, getArrayList(AbstractTypeObject.FIELD_NAME_TYPE_NAME, "VARCHAR(50) not null"));
        fields.put(x++, getArrayList(AbstractTypeObject.FIELD_NAME_TYPE_VALUE, "VARCHAR(255)"));

        // this.dumpFields(fields);
        return fields;
    }

    /**
     * gets the name of this type.
     * 
     * @return
     */
    public String getName() {
        return name;
    }

    // /**
    // * return the sql statement used to insert a new type object into the
    // database.
    // */
    // @Override
    // public String getSqlInsert() {
    // StringBuilder sqlStmt = new StringBuilder(super.getSqlInsert());
    // sqlStmt.append("\"").append(this.getName()).append("\",");
    // sqlStmt.append("\"").append(this.getDescription()).append("\"");
    // sqlStmt.append(");");
    // return sqlStmt.toString();
    // }
    //
    // /**
    // * return the sql statement used to update a type object in the database.
    // */
    // @Override
    // public String getSqlUpdate() {
    // StringBuilder sqlStmt = new StringBuilder(super.getSqlUpdate());
    // sqlStmt.append(" ").append(FIELD_NAME_TYPE_NAME).append("=\"").append(this.name).append("\"");
    // sqlStmt.append(",").append(FIELD_NAME_TYPE_VALUE).append("=\"").append(this.description).append("\"");
    //
    // sqlStmt.append(" where ").append(FIELD_NAME_UNIQUE_IDENTIFIER).append("=").append(this.uniqueIdentifier);
    // return sqlStmt.toString();
    // }

    /**
     * sets the description for this type.
     */
    public void setDescription(final String desc) {
        description = desc;
    }

    /**
     * sets the name of this type.
     */
    public void setName(final String nme) {
        name = nme;
    }

    /**
     * return a string representation of this type.
     */
    @Override
    public String toString() {
        final String meStr = name + (description.length() > 0 ? (":" + description) : "");
        return meStr;
    }
}
